<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>天气案例_监视属性</title>
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <div id="root">
           <h2>今天天气真的很{{info}}</h2>
           <button @click = "changeWeather()">点击切换天气</button>
           <hr/>
           <button @click = "thisInfo.a++">点击a加一</button>
        </div>
    </body>

    <script type="text/javascript">
        Vue.config.productionTip = false

        new Vue({
            el:"#root",
            data: {
                flag:true,
                thisInfo:{
                    a:1
                }
                
            }, 
            computed:{
                info(){
                    return this.flag ? '炎热': '寒冷'
                }
            },
            methods: {
                changeWeather(){
                    this.flag = !this.flag
                }
            },
            watch:{
                info:{
                    immediate:true, //初始化时调用handler
                    handler(newValue, oldValue){
                        console.log(newValue, oldValue)
                    }
                },
                thisInfo:{
                    deep:true, //开启深度监视
                    handler(value){
                        console.log(value.a)
                    }
                }
            }
        })
    </script>
</html>